<template>
    <div>
        <Header :left="true" leftText="返回" title="调机申请单明细页" />

        <!-- 滑动区域，适应手机分辨率 -->
        <div class="textScroll">
            <!-- 文字信息 -->
            <van-row style="margin-top: 10px">
                <van-col>
                    <van-image width="40" height="30" style="margin-left: -10px" src="assets/block.png" />
                </van-col>
                <van-col class="message" style="margin-top: 5px">调机申请单据信息</van-col>
            </van-row>

            <div class="divMessage">
                <Field v-model="item.Id" :readonly="true" size="small" class="Field" center colon label="调机单ID" />
                <Field v-model="item.ProductionDate" :readonly="true" size="small" class="Field" center colon
                    label="生产日期" />
                <Field v-model="item.POrderID" :readonly="true" size="small" class="Field" center colon label="生产订单" />
                <Field v-model="item.MaterialID" :readonly="true" size="small" class="Field" center colon label="物料编号" />
                <Field v-model="item.MaterialName" :readonly="true" size="small" class="Field" center colon label="物料名称" />
                <Field v-model="item.ProductionDate" :readonly="true" size="small" class="Field" center colon
                    label="生产时间" />
                <Field v-model="item.QProblemID" :readonly="true" size="small" class="Field" center colon label="异常原因" />
                <Field v-model="item.NoticeMemo" :readonly="true" size="small" class="Field" center colon label="通知单描述" />
                <Field v-model="item.ProductionBatch" :readonly="true" size="small" class="Field" center colon
                    label="生产批次" />
                <Field v-model="item.PShiftID" :readonly="true" size="small" class="Field" center colon label="班次" />
                <Field v-model="item.MachineID" :readonly="true" size="small" class="Field" center colon label="设备代码" />
                <Field v-model="item.SampleAmount" :readonly="true" size="small" class="Field" center colon label="抽样数量" />
                <Field v-model="item.AbnormalAmount" :readonly="true" size="small" class="Field" center colon
                    label="异常数量" />
                <Field v-model="result" :readonly="true" size="small" class="Field" center colon label="质量要求" />
                <Field v-model="item.Reasons" :readonly="true" size="small" class="Field" center colon label="需注明的缺陷描述" />
                <Field v-model="item.Creator" :readonly="true" size="small" class="Field" center colon label="调机申请QC" />
                <Field v-model="item.CreateDatetime" :readonly="true" size="small" class="Field" center colon
                    label="创建时间" />
                <Field v-model="item.AppearanceCheckRecord" :readonly="true" size="small" class="Field" center colon
                    label="外观检验记录：" />
                <Field class="Field" readonly="true" v-model="nowDate" label="扣货操作时间" />
                <Field class="Field" readonly="true" v-model="this.user.userName" label="扣货操作人" />
                <Field class="Field" v-model="item.DetainMemo" label="扣货备注" placeholder="请输入扣货备注" />
            </div>
            <div><br /></div>



            <van-row gutter="20">
                <van-col span="12">
                    <div style="margin: 16px">
                        <van-button color="#008792" round block type="info" @click="getRecord(form.AppearanceCheckRecord1)"
                            style="">查看外观检验不合格记录</van-button>
                    </div>
                </van-col>
                <van-col span="12">
                    <div style="margin: 16px">
                        <van-button color="#33a3dc" round block type="info" @click="checkSYS">查看实验室检验不合格项</van-button>
                    </div>
                </van-col>
            </van-row>

            <van-row gutter="20">
                <van-col span="12">
                    <div style="margin: 16px">
                        <van-button color="#1AB394" round block type="info" @click="openQA">打开质量辅助决策界面</van-button>
                    </div>
                </van-col>
                <van-col span="12">
                    <div style="margin: 16px">
                        <van-button color="#005831" round block type="info" @click="CheckTM">查看实验室复测记录</van-button>
                    </div>
                </van-col>
            </van-row>

            <div style="margin: 16px">
                <van-button color="#138087" round block type="info" native-type="submit" @click="submitsure">保存</van-button>
            </div>
        </div>
    </div>
</template>
<script>
import {
    Icon,
    NoticeBar,
    Button,
    Row,
    Tag,
    Checkbox,
    Pagination,
    popup,
    Loading,
    Popup,
    Panel,
    ImagePreview,
    Toast,
    tab,
    tabs,
    Divider,
    Image as VanImage,
    Field,
    CellGroup,
    Cell,
    Picker,
    Uploader,
    Dialog,
    Col,
    RadioGroup,
    Radio,
} from "vant";
import { _httpClient as _httpClientApi } from "@/libs/api";
import { _httpClient } from "@/libs/apisie";
import { storage } from "@/libs/utils";
Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(tab);
Vue.use(tabs);
Vue.use(Button);
Vue.use(Col);
Vue.use(Row);
Vue.use(Icon);
Vue.use(VanImage);
Vue.use(Divider);
Vue.use(Checkbox);
Vue.use(Pagination);
Vue.use(Panel);
Vue.use(Dialog);
Vue.use(Picker);
Vue.use(popup);
Vue.use(Uploader);
Vue.use(Loading);
Vue.use(Field);
Vue.use(RadioGroup);
Vue.use(Radio);
import Header from "@/components/header.vue";
import apicloud from "@/libs/apicloud";
export default {
    name: "QCWithholdgoodsMemorandumItem",
    components: {
        Button,
        NoticeBar,
        Header,
        ImagePreview,
        Icon,
        Row,
        tab,
        popup,
        Popup,
        tabs,
        Tag,
        VanImage,
        Toast,
        Divider,
        Field,
        CellGroup,
        Cell,
        Uploader,
        Picker,
        Dialog,
        Col,
        RadioGroup,
        Radio,
    },

    data() {
        return {
            btnLoading: false,
            winName: "", //窗口名
            user: [], //当前登录用户
            //多媒体文件
            photoList: [
                //图片
            ],
            pictureNum: 0, //照片数量
            playing: "播放中...", //语音播放中字幕
            audioLoad: false, // 语音播放中
            audioStop: true, // 语音暂停
            photoShow: false, //照片显示控制
            vedioShow: false, //视频显示控制
            audioShow: false, //语音显示控制
            vedioList: [], //视频
            audioPath: "", //语音
            searchKey1: "",
            resonShow: false, //暂停原因录入弹窗是否显示
            btnStartShow: false, //开始调机按钮权限
            btnAssignShow: true, //任务转派按钮权限
            btnStopShow: true, //调机暂停按钮权限
            btnEndShow: true, //调机结束按钮权限
            stopResonValue: "", //调机暂停原因
            showAppearanceCheckRecord: "",
            equipRepairVo: {
                id: null,
                eqKey: null,
                equipName: "",
                equipCode: "",
                remark: null,
                picList: [],
                videoList: [],
                audioList: [],
                resTime: null,
                requestUser: "",
                repairReson: "",
            },
            faultShowPicker: false, //故障原因下拉框
            screenWidth: 0,
            checked: true,
            active: 2,
            helpUser: [], //协助人
            helpUserStr: "", //协助人拼接字符串
            helpUserNameStr: "", //协助人拼接字符串
            helpUserContent: "", //协助人拼接字段
            faultType: "", //故障类型
            sparePart: [], //备件记录
            sparePartContent: "", //备件拼接字段
            fileUrl: "",
            form: [],
            faultTypes: [],
            stopReson: [],
            uploadSuccess: false,
            columnsDealType: [],
            columnsEmployee: [],
            columnsQProblem: [],
            columnsEmployeeND: [],
            columnsshift: [],
            showPickerEmployee: false,
            showPickerQProblem: false,
            item: {},
            valuepDealTypeName: "",
            EmployeeName: "",
            EmployeeName1: "",
            EmployeeName2: "",
            EmployeeName3: "",
            EmployeeName4: "",
            date1: "",
            date2: "",
            date3: "",
            date4: "",
            columnsEmployees: [],
            time: "",
            FactoryID: "",
            valuepShiftName: "",
            CheckTypeName: "",
            QProblemName: "",
            valueteamid: "",
            nowDate: "",
            EmployeeID: "",
            result: [],
            //领班
            QCLeaderAgreeValue: "",
            //带版主管
            TeamLeaderAgreeValue: "",
            //质量负责人
            QCManagerAgreeValue: "",
            //生产部门负责人
            PrdManagerAgreeValue: "",
            //利润点负责人
            FactoryManagerAgreeValue: "",
            //当前状态
            status: "",
            //是否显示人员
            showEmployee: false,
            PositionID: ""
        };
    },
    created: function () {
        let oldHight = api.winWidth;
        this.screenWidth = oldHight;
        this.user = JSON.parse(storage.get("user"));
        this.user.userId = this.user.userName;
        // this.equipRepairVo.resTime = this.getNowTime()
        //页面赋值
        this.item = api.pageParam.item;
        // alert(api.pageParam.item);
        this.initForm(api.pageParam.item);
        // // alert(JSON.stringify(this.form));
        this.nowDate = this.getNowTime();
        this.initList();
        this.getUsername(this.item.Creator)
        this.getUsername1(this.user.userName)
        this.getQualityProblems();
        this.getshift();
        this.getAppearanceCheckRoward()

    },
    watch: {  //实时监听搜索输入内容
        'searchKey': {
            handler(newVal) {
                let key = String(newVal);
                //alert(key);
                key = key.replace(/\s*/g, "");
                const reg = new RegExp(key, "ig");
                /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
                this.searchColumns = this.columnspline.filter(item => item.plineName.match(reg) != null);
                //alert(this.searchColumns);
            },
            deep: true,
            immediate: true,
        },

        'searchKey1': {
            handler(newVal) {
                let key = String(newVal);
                //alert(key);
                key = key.replace(/\s*/g, "");
                const reg = new RegExp(key, "ig");
                /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
                this.columnsEmployeeND = this.columnsEmployee.filter(item => item.EmployeeName.match(reg) != null);
                //alert(this.searchColumns);
            },
            deep: true,
            immediate: true,
        },

        'searchKey2': {
            handler(newVal) {
                let key = String(newVal);
                //alert(key);
                key = key.replace(/\s*/g, "");
                const reg = new RegExp(key, "ig");
                /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
                this.statColumn2 = this.statColumn.filter(item => item.POrderIDAndMaterialName.match(reg) != null);
                //alert(this.searchColumns);
            },
            deep: true,
            immediate: true,
        },
    },
    methods: {
        async initForm(val) {
            let _this = this;
            try {
                let res4 = await _httpClient.get(
                    _httpClient.getApiPrefix() + "/QualityAbnormalNotice/GetEntity?id=" + val)

                if (res4.Data.length > 0) {
                    _this.form = res4.Data[0]
                }
            } catch (e) {
                alert(JSOn.stringify(e))
            }
        },
        async getUsername(id) {

            try {

                let res4 = await _httpClient.get(
                    _httpClient.getApiPrefix() + "/Employee/GetList?EmployeeID=" + id)

                if (res4.Data.length > 0) {

                    this.item.Creator = res4.Data[0].EmployeeName
                    return
                }
            } catch (e) {
                alert(JSOn.stringify(e))
            }
            this.item.Creator = id
        },
        async getUsername1(id) {

            try {

                let res4 = await _httpClient.get(
                    _httpClient.getApiPrefix() + "/Employee/GetList?EmployeeID=" + id)

                if (res4.Data.length > 0) {

                    this.user.userName = res4.Data[0].EmployeeName
                    return
                }
            } catch (e) {
                alert(JSOn.stringify(e))
            }
            
        },

        getNowTime() {
            let dateTime;
            let yy = new Date().getFullYear();
            let mm = new Date().getMonth() + 1;
            let dd = new Date().getDate();
            let hh = new Date().getHours();
            let mf =
                new Date().getMinutes() < 10
                    ? "0" + new Date().getMinutes()
                    : new Date().getMinutes();
            let ss =
                new Date().getSeconds() < 10
                    ? "0" + new Date().getSeconds()
                    : new Date().getSeconds();
            dateTime = yy + "-" + mm + "-" + dd + " " + hh + ":" + mf + ":" + ss;
            return dateTime;
        },
        async initList() {
            if (this.form.Require1) {
                this.result.push("及时调机整改");
            }
            if (this.form.Require2) {
                this.result.push("停机调整");
            }
            if (this.form.Require3) {
                this.result.push("产品要求返工，发出返工通知单");
            }
            if (this.form.Require4) {
                this.result.push("在线自检挑出");
            }

            //判断审批流程状态
            if (!this.form.QCLeaderChecked) {
                //品管领班未审核
                this.status = 1;
            } else if (this.form.QCLeaderChecked && this.form.QCLeaderAgree && !this.form.TeamLeaderChecked) {//品管领班审核且同意,主管未审核
                //生产现场主管审核
                this.status = 2;
            } else if (this.form.TeamLeaderChecked && !this.form.TeamLeaderAgree && !this.form.PrdManagerChecked) {//生产现场主管已审核且不同意，生产部门负责人未审批
                //生产审核
                this.status = 3;
            } else if (this.form.PrdManagerChecked && !this.form.PrdManagerAgree && !this.form.QCManagerChecked) {//生产部门负责人审核且不同意 质量未审核
                //质量审核
                this.status = 4;
            } else if (this.form.QCManagerChecked && this.form.QCManagerAgree && !this.form.FactoryManagerChecked) {//质量负责人审核且同意 利润点未审批
                //利润点负责人审批
                this.status = 5;
                //alert("111")
            }

            try {
                if (this.form.QCLeaderUserID != "") {
                    let res4 = await _httpClient.get(
                        _httpClient.getApiPrefix() + "/Employee/GetList?EmployeeID=" + this.form.QCLeaderUserID)
                    this.QCLeaderAgreeValue = this.form.QCLeaderAgree ? "1" : "0"
                    this.date1 = this.form.QCLeaderCheckDatetime

                    if (res4.Data.length > 0) {
                        this.EmployeeName1 = res4.Data[0].EmployeeName
                    }
                }

                if (this.form.TeamLeaderUserID != "") {
                    let res4 = await _httpClient.get(
                        _httpClient.getApiPrefix() + "/Employee/GetList?EmployeeID=" + this.form.TeamLeaderUserID)
                    this.TeamLeaderAgreeValue = this.form.TeamLeaderAgree ? "1" : "0"
                    this.date2 = this.form.TeamLeaderCheckDatetime
                    if (res4.Data.length > 0) {
                        this.EmployeeName2 = res4.Data[0].EmployeeName
                    }
                }

                if (this.form.PrdMangerUserID != "") {
                    let res4 = await _httpClient.get(
                        _httpClient.getApiPrefix() + "/Employee/GetList?EmployeeID=" + this.form.PrdMangerUserID)
                    this.PrdManagerAgreeValue = this.form.PrdManagerAgree ? "1" : "0"
                    this.date3 = this.form.PrdManagerCheckDatetime
                    if (res4.Data.length > 0) {
                        this.EmployeeName3 = res4.Data[0].EmployeeName
                    }
                }

                if (this.form.QCMangerUserID != "") {
                    let res4 = await _httpClient.get(
                        _httpClient.getApiPrefix() + "/Employee/GetList?EmployeeID=" + this.form.QCMangerUserID)
                    this.QCManagerAgreeValue = this.form.QCManagerAgree ? "1" : "0"
                    this.date4 = this.form.QCManagerCheckDatetime
                    if (res4.Data.length > 0) {
                        this.EmployeeName4 = res4.Data[0].EmployeeName
                    }
                }

                // alert(JSON.stringify(this.form))
            } catch (e) {
                Toast(JSON.stringify(e))
            }
            // alert(JSON.stringify(this.form))

        },
        openQA() {
            let _this = this
            // alert(_this.form.POrderID)
            api.openWin({
                name: 'qAssistance',
                url: './qAssistance-qualityAssistance.html',
                pageParam: {
                    POrderID: _this.form.POrderID,
                    PlineID: _this.form.MachineID
                }
            });
        },
        getRecord(id) {
            if (id = "" || id == 0 || id == null) {
                alert("没有外观检验不合格记录");
                return;
            }
            api.openWin({
                name: 'qCcheckReview',
                url: './quality-qCcheckReview.html',
                pageParam: {
                    id: id
                }
            });
        },
        async CheckTM() {
            let id = this.form.LaboratoryCheckRecord1
            let CheckItem = this.form.CheckItem;
            let CheckBatch = this.form.CheckBatch;
            if (CheckBatch == "全项检验") {
                CheckBatch = "问题产品复核检验-全项"
            }
            else {
                CheckBatch = "问题产品复核检验-过程"
            }

            if (id == "" || id == null || id == undefined) {
                Toast.clear()
                Toast.fail("当前没有维护实验室复测记录，无法获取复测记录！")
                return
            }
            api.openWin({
                name: 'viewlaboratorytest1',
                url: './equipmentsj-viewlaboratorytest1.html',
                pageParam: {
                    id: this.form.LaboratoryCheckRecord1,
                    CheckBatch: CheckBatch,
                    CheckItem: this.form.CheckItem
                }
            });
        },
        async checkSYS() {
            let id = this.form.LaboratoryCheckRecord1;
            let CheckBatch = this.form.CheckBatch;
            let CheckItem = this.form.CheckItem;
            if (id == "" || id == null || id == undefined) {
                Toast.clear()
                Toast.fail("当前没有维护实验室检验记录，无法获取不合格记录！")
                return
            }
            api.openWin({
                name: 'viewlaboratorytest',
                url: './equipmentsj-viewlaboratorytest.html',
                pageParam: {
                    id: this.form.LaboratoryCheckRecord1,
                    CheckBatch: this.form.CheckBatch,
                    CheckItem: this.form.CheckItem
                }
            });
        },
        async getAppearanceCheckRoward() {
            try {
                let res = await _httpClient.get(
                    _httpClient.getApiPrefix() +
                    "/QualityAppearanceCheck/GetEntityName?FieldValue=" + this.form.AppearanceCheckRecord1);
                if (res.HttpCode === "200") {
                    this.showAppearanceCheckRecord = res.Data
                } else {
                    this.showAppearanceCheckRecord = this.form.AppearanceCheckRecord1
                }

            } catch (e) {
                Toast.fail(JSON.stringify(e));
            }
        },
        //提交审批
        submitCheck() {
            var body = {};
            body.Id = this.form.Id;
            //判断状态
            if (this.status == 1) {
                //质量制程主管
                body.QCLeaderAgree = this.form.QCLeaderAgree;
                body.QCLeaderMemo = this.form.QCLeaderMemo;
                body.QCLeaderUserID = this.user.userId;
                body.QCLeaderCheckDatetime = this.nowDate;
                body.QCLeaderChecked = true;
                //需要调机 选择生产现场主管
                if (this.form.QCLeaderAgree) {
                    body.TeamLeaderUserID = this.EmployeeID
                    this.sendmessage(1, false, false);
                } else {
                    //不需要调机 直接结束     
                    //传入终审人
                    body.FixedMan = this.user.userId;
                    //最终审时间
                    body.FixedDatetime = this.nowDate;
                    //终审是否需要调机
                    body.FixedAgree = false;

                    this.sendmessage(1, true, false);
                }
            } else if (this.status == 2) {
                //生产现场主管审核
                body.TeamLeaderAgree = this.form.TeamLeaderAgree;
                body.TeamLeaderMemo = this.form.TeamLeaderMemo;
                body.TeamLeaderCheckDatetime = this.nowDate;
                body.TeamLeaderChecked = true;
                //需要调机 直接结束
                if (this.form.TeamLeaderAgree) {
                    //传入终审人
                    body.FixedMan = this.user.userId;
                    //最终审时间
                    body.FixedDatetime = this.nowDate;
                    //终审是否需要调机
                    body.FixedAgree = true;

                    this.sendmessage(2, true, true);
                } else {
                    //不需要调机 询问生产部门负责人     
                    body.PrdMangerUserID = this.EmployeeID;

                    this.sendmessage(2, false, false);
                }
            } else if (this.status == 3) {
                //生产部门负责人审核
                body.PrdManagerAgree = this.form.PrdManagerAgree;
                body.PrdMangerMemo = this.form.PrdMangerMemo;
                body.PrdManagerCheckDatetime = this.nowDate;
                body.PrdManagerChecked = true
                //需要调机 直接结束
                if (this.form.PrdManagerAgree) {
                    //传入终审人
                    body.FixedMan = this.user.userId;
                    //最终审时间
                    body.FixedDatetime = this.nowDate;
                    //终审是否需要调机
                    body.FixedAgree = true;

                    this.sendmessage(3, true, true);
                } else {
                    //不需要调机 选择质量负责人   
                    body.QCMangerUserID = this.EmployeeID;

                    this.sendmessage(3, false, false);
                }
            } else if (this.status == 4) {//质量负责人审核
                body.QCManagerAgree = this.form.QCManagerAgree;
                body.QCMangerMemo = this.form.QCMangerMemo;
                body.QCManagerCheckDatetime = this.nowDate;
                body.QCManagerChecked = true;
                //需要调机 选择利润点负责人
                if (this.form.QCManagerAgree) {
                    body.FactoryMangerUserID = this.EmployeeID;
                    this.sendmessage(4, false, false);
                } else {
                    //不需要调机 直接结束              
                    //传入终审人
                    body.FixedMan = this.user.userId;
                    //最终审时间
                    body.FixedDatetime = this.nowDate;
                    //终审是否需要调机
                    body.FixedAgree = false;
                    this.sendmessage(4, true, false);
                }
            } else if (this.status == 5) {
                //利润点负责人审核
                body.FactoryManagerAgree = this.form.FactoryManagerAgree;
                body.FactoryMangerMemo = this.form.FactoryMangerMemo;
                body.FactoryManagerCheckDatetime = this.nowDate;
                body.FactoryManagerChecked = true;
                //传入终审人
                body.FixedMan = this.user.userId;
                //最终审时间
                body.FixedDatetime = this.nowDate;
                //需要调机 直接结束 
                if (this.form.FactoryManagerAgree) {
                    //终审是否需要调机
                    body.FixedAgree = true;
                    this.sendmessage(5, true, true);
                } else {
                    //不需要调机 直接结束    
                    //终审是否需要调机
                    body.FixedAgree = false;
                    this.sendmessage(5, true, false);
                }
            }
            //alert(JSON.stringify(body))
            this.SaveCheckEntity(body)
            //发送调机终审消息
            // if (body.FixedMan == this.user.userId) {

            // }
        },
        //审核节点，是否终审，是否同意
        async sendmessage(index, isfix, isend) {
            try {
                let _this = this;

                let eventDescription = "";
                let eventDatetime = _this.getNowTime();
                let eventTypeID = "N3";
                let eventID = "";
                let messageContent = "";
                let msgContentTypeID = "";
                let pLineID = _this.form.MachineID;
                let machineID = "";
                let pShiftID = "";
                let teamID = "";
                let pOrderID = "";
                let productionBarcode = "";
                let materialBarcode = "";
                let relatedEmployee = "";
                let messageStatus = "";
                let processBatchID = "";
                let beginDatetime = _this.getNowTime();
                let sendFinished = false;
                let closed = false;

                let msg1 = "同意调机，请调机人员按照要求进行调机！";
                let msg2 = "不同意调机，请相关岗位知悉！";


            } catch (error) {
                alert(error);
            }

        },
        async SaveCheckEntity(body) {
            let _this = this;
            Toast.loading({
                mask: true,
                forbidClick: true,
                duration: 0,
                message: "请稍等...",
            });
            try {
                let res = await _httpClient.post(
                    _httpClient.getApiPrefix() + "/QualityAbnormalNotice/SaveEntity",
                    {
                        body: body,
                    }
                );
                if (res.Message != null) {
                    //message不为空,有报错信息，打卡失败 暂时这样判断
                    Toast.clear();
                    Toast.fail("保存失败,请核对信息！");
                } else {
                    //打卡成功
                    Toast.clear();
                    Toast.success("保存成功！");
                    setTimeout(function () {
                        _this.$ac.closeWin();
                    }, 1000);
                }
            } catch (e) {
                Toast.fail(JSON.stringify(e));
            }
        },
        //获取员工列表
        async getEmployeeID() {
            this.columnsEmployee = []
            // alert(_httpClient.getApiPrefix() + "/Employee/GetList?PositionID=" + this.PositionID)
            let _this = this;
            try {
                let res = await _httpClient.get(
                    _httpClient.getApiPrefix() + "/Employee/GetList?PositionID=" + this.PositionID,
                );
                if (res.HttpCode === "200") {
                    let temp = res.Data.map(item => ({ EmployeeID: item.EmployeeID, EmployeeName: item.EmployeeName }))
                    temp.forEach(item => {
                        _this.columnsEmployee.push(item);
                        _this.columnsEmployeeND.push(item);
                    })
                }
            } catch (e) {
                Toast.fail(JSON.stringify(e));
            }
        },

        //获取员工列表
        async getEmployeeID1() {
            let _this = this;
            try {
                let res = await _httpClient.get(
                    _httpClient.getApiPrefix() + "/Employee/GetList?PositionID=GW35",
                );
                if (res.HttpCode === "200") {
                    let temp = res.Data.map(item => ({ EmployeeID: item.EmployeeID, EmployeeName: item.EmployeeName }))
                    temp.forEach(item => {
                        _this.columnsEmployee.push(item);
                        _this.columnsEmployeeND.push(item);
                    })
                }
            } catch (e) {
                Toast.fail(JSON.stringify(e));
            }
        },


        //获取班次信息
        async getshift() {
            let _this = this;
            try {
                let res = await _httpClient.get(
                    _httpClient.getApiPrefix() + "/ProductionShift/GetList?factoryID=" + _this.form.FactoryID,
                );
                if (res.HttpCode === "200") {
                    for (let index = 0; index < res.Data.length; index++) {
                        if (res.Data[index].Actived == false) {
                            delete res.Data[index];
                        }
                    }
                    let shiftMap = res.Data.map(item => ({ pShiftName: item.PShiftName, pShiftID: item.PShiftID }))
                    _this.columnsshift = shiftMap
                }
            } catch (e) {
                Toast.fail(JSON.stringify(e));
            }
        },
        showShiftIDName(pShiftID) {
            var pShiftName;
            this.columnsshift.forEach(item => {
                if (item.pShiftID === pShiftID) {
                    pShiftName = item.pShiftName;

                }
            })
            return pShiftName
        },
        showQProblemID(QProblemID) {
            var QProblemName;
            this.columnsQProblem.forEach(item => {
                if (item.QProblemID === QProblemID) {
                    QProblemName = item.QProblemName;
                }
            })
            return QProblemName;
        },
        showDealType(type) {
            var DealTypeName;
            this.columnsDealType.forEach(item => {
                if (item.DealTypeID === type) {
                    DealTypeName = item.DealTypeName;
                }
            })
            return DealTypeName;
        },
        changeAgreeValue(index) {

            if (this.status != index) {
                return
            }

            //如果合格 隐藏页面 直接提交
            if (index == 1) {
                this.EmployeeName1 = ""
                this.EmployeeID = ""
                if (this.QCLeaderAgreeValue == "1") {
                    this.columnsEmployeeND = [];
                    this.form.QCLeaderAgree = true;
                    this.form.QCLeaderMemo = this.getNowTime() + ":" + "品管领班:" + this.user.employeeName + "同意调机!"
                    this.showEmployee = true;
                    this.PositionID = "GW34";
                    this.getEmployeeID();
                    this.getEmployeeID1();
                } else if (this.QCLeaderAgreeValue == "0") {
                    //若不同意
                    this.form.QCLeaderAgree = false;
                    this.form.QCLeaderMemo = this.getNowTime() + ":" + "品管领班:" + this.user.employeeName + "不同意调机!"
                    this.showEmployee = false;
                }
            }
            if (index == 2) {
                this.EmployeeName2 = ""
                this.EmployeeID = ""
                if (this.TeamLeaderAgreeValue == "1") {
                    //若主管同意
                    this.form.TeamLeaderAgree = true;
                    this.form.TeamLeaderMemo = this.getNowTime() + ":" + "生产现场主管:" + this.user.employeeName + "同意调机!"
                    this.showEmployee = false;
                } else if (this.TeamLeaderAgreeValue == "0") {
                    this.columnsEmployeeND = [];
                    //若主管不同意
                    this.form.TeamLeaderAgree = false;
                    this.form.TeamLeaderMemo = this.getNowTime() + ":" + "生产现场主管:" + this.user.employeeName + "不同意调机!"
                    this.showEmployee = true;
                    //this.PositionID = "GW20";
                    //this.getEmployeeID();
                    this.getEmployeeIDOfGW20GW36();
                }
            }

            if (index == 4) {
                this.EmployeeName4 = ""
                this.EmployeeID = ""
                if (this.QCManagerAgreeValue == "1") {

                    this.columnsEmployeeND = [];
                    //若质量负责人同意
                    this.form.QCManagerAgree = true;
                    this.form.QCMangerMemo = this.getNowTime() + ":" + "质量负责人:" + this.user.employeeName + "同意调机!";
                    this.showEmployee = true;
                    this.PositionID = "GW01";
                    this.getEmployeeID();
                } else if (this.QCManagerAgreeValue == "0") {
                    //若质量负责人不同意
                    this.form.QCManagerAgree = false;
                    this.form.QCMangerMemo = this.getNowTime() + ":" + "质量负责人:" + this.user.employeeName + "不同意调机!";
                    this.showEmployee = false;
                }
            }

            if (index == 3) {
                this.EmployeeName3 = ""
                this.EmployeeID = ""
                if (this.PrdManagerAgreeValue == "1") {
                    //若生产部门负责人同意
                    this.form.PrdManagerAgree = true;
                    this.form.PrdMangerMemo = this.getNowTime() + ":" + "生产部门负责人:" + this.user.employeeName + "同意调机!"
                    this.showEmployee = false;
                } else if (this.PrdManagerAgreeValue == "0") {
                    this.columnsEmployeeND = [];
                    //若生产负责不人同意
                    this.form.PrdManagerAgree = false;
                    this.form.PrdMangerMemo = this.getNowTime() + ":" + "生产部门负责人:" + this.user.employeeName + "不同意调机!"
                    this.showEmployee = true;
                    this.PositionID = "GW07";
                    this.getEmployeeID();
                }
            }

            if (index == 5) {
                if (this.FactoryManagerAgreeValue == "1") {
                    //若利润点负责人同意
                    this.form.FactoryManagerAgree = true;
                    this.form.FactoryMangerMemo = this.getNowTime() + ":" + "利润点负责人:" + this.user.employeeName + "同意调机!"
                } else if (this.FactoryManagerAgreeValue == "0") {
                    //若利润点负责不人同意
                    this.form.FactoryManagerAgree = false;
                    this.form.FactoryMangerMemo = this.getNowTime() + ":" + "利润点负责人:" + this.user.employeeName + "不同意调机!"
                }
            }

        },

        async submitsure() {
            var _this = this;
            Toast.loading({
                mask: true,
                forbidClick: true,
                duration: 0,
                message: "请稍等...",
            });
            //Toast.fail(JSON.stringify(_this.result));
            try {
                let res = await _httpClient.post(
                    _httpClient.getApiPrefix() + "/QualityAbnormalNotice/SaveEntity",
                    {
                        body: {
                            QCLeaderChecked: true,
                            TeamLeaderChecked: true,
                            QCManagerChecked: true,
                            PrdManagerChecked: true,
                            FactoryManagerChecked: true,
                            DetainChecked: true,

                            Id: _this.item.Id,
                            ProductionDate: _this.item.ProductionDate,
                            POrderID: _this.item.POrderID,
                            MaterialName: _this.item.MaterialName,
                            Reasons: _this.item.Reasons,
                            MaterialID: _this.item.MaterialID,
                            ProDatetimeFrom: _this.item.ProDatetimeFrom,
                            ProDatetimeTo: _this.item.ProDatetimeTo,
                            QProblemID: _this.item.QProblemID,
                            FactoryID: "TC00",
                            ResourceFrom: _this.item.ResourceFrom,
                            PShiftID: _this.item.PShiftID,
                            ProductionBatch: _this.item.ProductionBatch,
                            MachineID: _this.item.MachineID,
                            SampleAmount: _this.item.SampleAmount,
                            AbnormalAmount: _this.item.AbnormalAmount,
                            ProductionColor: _this.item.ProductionColor,
                            NoticeMemo: _this.item.NoticeMemo,
                            Creator: _this.item.userName,
                            Require4: _this.item.Require4,
                            Require3: _this.item.Require3,
                            Require2: _this.item.Require2,
                            Require1: _this.item.Require1,
                            AbnormalDescription: _this.item.AbnormalDescription,
                            LaboratoryCheckRecord1: _this.item.LaboratoryCheckRecord1,
                            AppearanceCheckRecord1: _this.item.AppearanceCheckRecord1,
                            DetainUserID: _this.item.Creator,
                            DetainMemo: _this.item.DetainMemo,
                            FixedMan: _this.user.userId

                        },
                    }
                );
                //alert(body.DetainUserID);
                if (res.Message != null) {
                    //message不为空,有报错信息，打卡失败 暂时这样判断
                    Toast.clear();
                    Toast.fail("保存失败,请核对信息！");
                } else {
                    //打卡成功
                    _this.sendmessage();
                    Toast.clear();
                    Toast.success("保存成功！");
                    setTimeout(function () {
                        _this.$ac.closeWin();
                    }, 2000);
                }
            } catch (e) {
                Toast.fail(JSON.stringify(e));
            }
        },

    },
};
</script>
<style>
body {
    background-color: White;
}

.pic {
    width: 100%;
    text-align: center;
}

.clickbtn {
    width: 1;
    margin: 5px 10px;
    line-height: 45px;
    border: 1px #ccc dashed;
    text-align: center;
}

.buttonColor {
    background-color: #ff9933;
    border-color: #ff9933;
}

.buttonColor2 {
    background-color: #1076c0;
    border-color: #1076c0;
}

.message {
    font-size: 15px;
    margin-top: 5px;
    margin-left: -10px;
    font-weight: bold;
}

.divStyle {
    border: 1px solid #dcdcdc;
    border-top-width: 3px;
    border-left-width: 3px;
    margin-left: 5px;
    margin-right: 4px;
    margin-top: 4px;
}

.pagination {
    position: fixed;
    bottom: 15px;
    width: 300px;
    margin-left: 10%;
    color: rgb(0, 0, 255);
    text-align: center;
}

.divMedia {
    margin-top: 0px;
    height: 230px;
    border: solid #dcdcdc;
    margin-left: 5px;
    margin-right: 15px;
    border-top-width: 4px;
    border-left-width: 4px;
    border-right-width: 1px;
    border-bottom-width: 1px;
}

.divMedia2 {
    margin-top: 0px;
    height: 160px;
    border: solid #dcdcdc;
    margin-left: 5px;
    margin-right: 15px;
    border-top-width: 4px;
    border-left-width: 4px;
    border-right-width: 1px;
    border-bottom-width: 1px;
}

.button {
    position: fixed;
    left: 5px;
    right: 5px;
    bottom: 24px;
    width: 100%;
    height: 30px;
    font-size: 12px;
}

.divMessage {
    margin-top: 0px;
    border: solid #dcdcdc;
    margin-left: 5px;
    margin-right: 15px;
    border-top-width: 4px;
    border-left-width: 4px;
    border-right-width: 1px;
    border-bottom-width: 1px;
}

.Field {
    font-weight: bold;
    font-size: 15px;
    color: #9c8e8e;
    height: 45px;
}

.Field2 {
    font-weight: bold;
    font-size: 15px;
    color: #9c8e8e;
}

.textScroll {
    display: inline-block;
    position: fixed;
    top: 5rem;
    bottom: 0rem;
    overflow: scroll;
    right: 0;
    width: 100%;
    z-index: 1;
}
</style>
  